// pages/my/mydetailed/detailedOrder/detailedOrder.js
import Dialog from '@vant/weapp/dialog/dialog';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        orderId: "",
        orderData: {},
        amount: 0,

    },
    //   获取数据
    getList() {
        wx.request({
            url: 'http://admin.bsmall.byesame.com/wx/order/detail',
            data: {
                orderId: this.data.orderId
            },
            method: "GET",
            header: {
                'x-byesame-token': wx.getStorageSync('token')
            },
            success: (res) => {
                // console.log("这是成功的",res);
                if (res.data.errno == 0) {
                    this.setData({
                        orderData: res.data.data,
                    })
                    // amount:res.data.data.orderGoods
                    for (let i = 0; i < res.data.data.orderGoods.length; i++) {
                        this.setData({
                            amount: this.data.amount + res.data.data.orderGoods[i].price
                        })

                    }
                    console.log("这是总金额", this.data.amount);
                    console.log("这是orderData", this.data.orderData);
                }
            },
            fail: (err) => {
                console.log("这是失败的", err);
            }
        })
    },
    //   取消订单
    cancelOrder() {
        Dialog.confirm({
                title: '确定要取消改订单吗？',
            })
            .then(() => {
                // on confirm
                wx.request({
                    url: 'http://admin.bsmall.byesame.com/wx/order/cancel',
                    data: {
                        orderId: this.data.orderId
                    },
                    method: "POST",
                    header: {
                        'x-byesame-token': wx.getStorageSync('token')
                    },
                    success: (res) => {
                        if (res.data.errno == 0) {
                            console.log("删除成功");
                            wx.navigateBack({
                                delta: 1
                            })
                        }
                    }

                })
            })
            .catch(() => {
                // on cancel
            });


    },
    //前往支付页面
    toPay(e){
        wx.navigateTo({
            url: '../../../payment/payment?orderId=' + e.currentTarget.dataset.orderid,
        })
    },
   
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        console.log("这里是订单id", options);
        this.setData({
            orderId: options.orderId

        })
        this.getList()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})